<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * 用户管理控制器
 */
class Stock_model extends CI_Model {
	/**
	 * 添加客户的方法
	 */
	public function add($data){
		if($this->db->insert('stock',$data)){
			return true;
		}else{
			return false;
		}
	}

	public function edit($data){

		return $this->db->where(array('id'=>$data['id']))->update('stock', $data);
	}

	//获取一个订单
	public function getOrderOne($where){
		return $this->db->where($where)->get('stock')->row_array();
	}

	public function getEditNum($where){
		return $this->db->where($where)->get('stock')->row_array();
	}
	/**
	 * 获取列表的方法
	 */
	public function lists(){
		return $this->db->select("s.id,s.time,s.number,s.tax,s.note,s.price,s.is_payment,s.total,s.alltotal,u.name as username,c.name,s.operator,s.price1,s.number1,s.lasteditoperator,s.stillneedtopay")->from('category as c')->join('stock as s',"c.id = s.cid")->join("users as u","u.id=s.uid")->order_by("s.id","DESC")->get()->result_array();
	}
	/**
	 * 列表获取总条数的方法
	 */
	public function listsNum(){
		return $this->db->from('category as c')->join('stock as s',"c.id = s.cid")->join("users as u","u.id=s.uid")->get()->num_rows();
	}
	/**
	 * 根据日期获取对应的数据
	 */
	public function searchList($where,$rows,$page){
		return $this->db->select("s.id,s.time,s.number,s.tax,s.note,s.price,is_payment,s.total,s.alltotal,u.name as username,c.name,s.operator,s.price1,s.number1,s.lasteditoperator,s.stillneedtopay")->from('category as c')->join('stock as s',"c.id = s.cid")->join("users as u","u.id=s.uid")->where($where)->order_by("s.id","DESC")->limit($rows,$rows*($page-1))->get()->result_array();
	}

	/**
	 * 根据日期获取对应总条数的方法
	 */
	public function searchListNum($where){
		return $this->db->from('category as c')->join('stock as s',"c.id = s.cid")->join("users as u","u.id=s.uid")->where($where)->get()->num_rows();
	}

}